import { Inject, Injectable } from '@nestjs/common';
import { ConfigModule, ConfigService, ConfigType } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
import database from './database';
@Injectable()
export class TypeOrmConfig implements TypeOrmOptionsFactory {
  constructor(@Inject(database.KEY) private databaseConfig:ConfigType<typeof database>) {

  }
  createTypeOrmOptions(connectionName?: string): TypeOrmModuleOptions {
    return {
      type: 'mysql',
      host: this.databaseConfig.host,
      port: 3306,
      username: this.databaseConfig.username,
      password: this.databaseConfig.password,
      database: this.databaseConfig.database,
      synchronize: true,
      autoLoadEntities: true,
    };
  }
}
